package com.daluzy.chmanager.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.daluzy.chmanager.MyApplication;
import com.daluzy.chmanager.R;
import com.daluzy.chmanager.adapter.RecordAdapter;
import com.daluzy.chmanager.adapter.SchoolAdapter;
import com.daluzy.chmanager.bean.Record;
import com.daluzy.chmanager.bean.School;
import com.xiasuhuei321.loadingdialog.view.LoadingDialog;

import java.util.List;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * 我的反馈
 */
public class MyRecordActivity extends AppCompatActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rv_data)
    RecyclerView rvData;
    private LoadingDialog loadingDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_record_daluzy);
        ButterKnife.bind(this);
        loadingDialog = new LoadingDialog(this);
        rvData.setLayoutManager(new LinearLayoutManager(this));
    }

    private void initData() {
        if (loadingDialog != null)
            loadingDialog.show();
        BmobQuery<Record> query = new BmobQuery<>();
        query.addWhereEqualTo("record_student", MyApplication.getIntance().getStudents().getStudent_name());
        query.findObjects(new FindListener<Record>() {
            @Override
            public void done(List<Record> object, BmobException e) {
                if (e == null) {
                    if (object != null && object.size() > 0) {
                        RecordAdapter recordAdapter = new RecordAdapter(MyRecordActivity.this, object);
                        rvData.setAdapter(recordAdapter);
                    }
                } else {
                    Toast.makeText(MyRecordActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
                }
                if (loadingDialog != null)
                    loadingDialog.close();
            }
        });
    }

    @OnClick({R.id.iv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;

        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }
}
